260 ASSIGN @System TO WIDGET "SYSTEM";SET ("*LOAD":"HELP_EX/SBEVNTS.SCR")
270 STATUS @System;RETURN ("*WIDGETS":Num_widgets)
280 ALLOCATE Names$(1:Num_widgets)[80]
290 STATUS @System;RETURN ("*WIDGET NAMES":Names$(*))
300 GOSUB Init
310 !
320 ! Set up events
330 !
340 CONTROL @System;SET ("*NAME":Names$(Meter),"ALARM TYPE":"EVENT","ALARM RANGES":"HIGH,MIDDLE,LOW")
350 ON EVENT @System,"CHANGED" GOSUB Event_handler
360 ON EVENT @System,"ALARM",2 GOSUB Event_handler
370 ON EVENT @System,"ACTIVATED" GOSUB Event_handler
380 ON EVENT @System,"SYSTEM MENU" GOSUB Event_handler
390 !
400 REPEAT
410 WAIT FOR EVENT
420 UNTIL NOT Keep_looping
430 !
440 STOP
450 !
460 Init:!
470 Queuing=0
480 CONTROL @System;SET ("*NAME":Names$(Toggle),"VALUE":Queuing,"*QUEUE EVENTS":Queuing)
490 Min=0.
500 Max=100.0
510 Low_lim=25.0
520 High_lim=75.0
530 GOSUB Set_limits
540 CONTROL @System;SET ("*NAME":Names$(Slider),"VALUE":Min)
550 CONTROL @System;SET ("*NAME":Names$(Meter),"VALUE":Min)
560 CONTROL @System;SET ("*NAME":Names$(Bar),"VALUE":Min)
570 !
580 ! Send names to PRINTER widget
590 !
600 CONTROL @System;SET ("*NAME":Names$(Printer),"HIDDEN LINES":1000)
610 CONTROL @System;SET ("TEXT":"This example contains "&VAL$(Num_widgets)&" widgets:")
620 CONTROL @System;SET ("APPEND TEXT":"")
630 CONTROL @System;SET ("APPEND TEXT":Names$(*))
640 CONTROL @System;SET ("APPEND TEXT":"")
650 RETURN
660 !
670 Set_limits:!
680 CONTROL @System;SET ("*NAME":Names$(Meter),"LOW LIMIT":Low_lim,"HIGH LIMIT":High_lim)
690 CONTROL @System;SET ("*NAME":Names$(Bar),"LOW LIMIT":Low_lim,"HIGH LIMIT":High_lim)
700 RETURN
710 !
720 Event_handler:!
730 REPEAT
740 STATUS @System;RETURN ("*QUEUED EVENT":Event$(*),"*QUEUED EVENTS":Queued)
750 SELECT Event$(1)
760 CASE "ACTIVATED"
770 SELECT VAL(Event$(0)[LEN(Event$(0))])
780 CASE 1
790 DIALOG "NUMBER","Enter new LOW LIMIT",Btn;SET ("REAL NOTATION":"FIXED","REAL RESOLUTION":3,"MINIMUM":Min,"MAXIMUM":Max,"VALUE":Low_lim),RETURN ("VALUE":Value)
800 IF Btn=0 THEN
810 Low_lim=Value
820 GOSUB Set_limits
830 END IF
840 CASE 2
850 DIALOG "NUMBER","Enter new HIGH LIMIT",Btn;SET ("REAL NOTATION":"FIXED","REAL RESOLUTION":3,"MINIMUM":Min,"MAXIMUM":Max,"VALUE":High_lim),RETURN ("VALUE":Value)
860 IF Btn=0 THEN
870 High_lim=Value
880 GOSUB Set_limits
890 END IF
900 END SELECT
910 CASE "CHANGED"
920 IF Queued THEN GOSUB Flush_queue
930 SELECT Event$(0)
940 CASE Names$(Slider)
950 STATUS @System;RETURN ("*NAME":Names$(Slider),"VALUE":Value)
960 CONTROL @System;SET ("*NAME":Names$(Meter),"VALUE":Value)
970 CASE Names$(Toggle)
980 STATUS @System;RETURN ("*NAME":Names$(Toggle),"VALUE":Queuing)
990 CONTROL @System;SET ("*QUEUE EVENTS":Queuing)
1000 END SELECT
1010 CASE "ALARM"
1020 IF Queued THEN GOSUB Flush_queue
1030 STATUS @System;RETURN ("*NAME":Names$(Meter),"VALUE":Value)
1040 CONTROL @System;SET ("*NAME":Names$(Bar),"VALUE":Value)
1050 CASE "" ! No events queued
1060 CASE ELSE ! SYSTEM MENU
1070 IF Queuing THEN
1080 System_event=VAL(Event$(1)[13])
1090 ELSE
1100 STATUS @System;RETURN ("*NAME":Names$(Panel),"SYSTEM MENU EVENT":System_event)
1110 END IF
1120 SELECT System_event
1130 CASE 0
1140 GOSUB Init
1150 CASE 1
1160 DIALOG "QUESTION","Do you want to quit?",Keep_looping
1170 END SELECT
1180 END SELECT
1190 UNTIL NOT Queued
1200 RETURN
1210 !
1220 Flush_queue:!
1230 CONTROL @System;SET ("*EVENT WIDGET FILTER":Event$(0),"*EVENT NAME FILTER":Event$(1))
1240 STATUS @System;RETURN ("*FLUSH QUEUED EVENTS":Flushed,"*QUEUED EVENTS":Queued)
1250 CONTROL @System;SET ("*EVENT WIDGET FILTER":"","*EVENT NAME FILTER":"")
1260 IF Flushed THEN
1270 CONTROL @System;SET ("*NAME":Names$(Printer),"APPEND TEXT":"Flushed "&VAL$(Flushed)&" "&Event$(0)&":"&Event$(1)&" events.")
1280 CONTROL @System;SET ("APPEND TEXT":" "&VAL$(Queued)&" events remaining")